package com.bing.sina;

import com.bing.Impl.AbstrcatStep;
import com.bing.util.Context;
import com.bing.util.DriverFactory;
import com.bing.util.TaoBao;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.util.List;

/**
 * Created by Administrator on 2014/7/3.
 */
public class TaoShua implements Runnable {

    private AbstrcatStep step;
    private String username;
    private String password;
    private TaoListener taoListener;
    private String browse;
    private String _weiBoId;
    private boolean forceUpdate;


    public TaoShua(AbstrcatStep step, String browse, String _weiBoId, String username, String password, boolean forceUpdate, TaoListener taoListener) {
        this.step = step;
        this.browse = browse;
        this.username = username;
        this.password = password;
        this.taoListener = taoListener;
        this._weiBoId = _weiBoId;
        this.forceUpdate = forceUpdate;
    }

    @Override
    public void run() {
        Context context = new Context();
        context.setUserName(username);
        context.setPassWord(password);
        context.setTaoListener(taoListener);
        WebDriver driver = DriverFactory.getDriver(browse);
        context.setDriver(driver);
        context.setWait(new WebDriverWait(driver, 10));
        List<String> weiBoIds = TaoBao.getWeiBoIds(_weiBoId);
        taoListener.setTitle("(0/" + weiBoIds.size() + ")");
        context.setSetting(Context.WEIBOID, weiBoIds);
        context.setSetting(Context.GONEXT, true);
        context.setSetting(Context.FORCE_UPDATE, forceUpdate);
        step.start(context);
    }
}
